package com.example.androidproject.app.deprecated.temporarily_deprecated_adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.androidproject.utils.ResultsConstant;
import com.example.androidproject.R;

public class ClassifyContentAdapter2 extends BaseAdapter {

    private final Context mContext;
    private final int classifyType;

    public ClassifyContentAdapter2(Context mContext, int classifyType) {
        this.mContext = mContext;
        this.classifyType = classifyType;
    }

    @Override
    public int getCount() {
        int size = 0;
        if (classifyType == 1) {
            size = ResultsConstant.MovieList.size();
        }
        if (classifyType == 2) {
            size = ResultsConstant.NovelList.size();
        }
        return size;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.classify_content_item, null);
            viewHolder.iv_classify_content = convertView.findViewById(R.id.iv_classify_content);
            viewHolder.tv_classify_content = convertView.findViewById(R.id.tv_classify_content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
//        if (ResultsConstant.isScrolling) {
//            viewHolder.iv_classify_content.setImageResource(0);
//        } else {
        if (classifyType == 1) {
            Glide.with(mContext).load(ResultsConstant.MovieList.get(position).getSrc()).into(viewHolder.iv_classify_content);
            viewHolder.tv_classify_content.setText(ResultsConstant.MovieList.get(position).getName());
        }
        if (classifyType == 2) {
            Glide.with(mContext).load(ResultsConstant.NovelList.get(position).getImage()).into(viewHolder.iv_classify_content);
            viewHolder.tv_classify_content.setText(ResultsConstant.NovelList.get(position).getTitle());
        }
//        }
        return convertView;
    }

    public class ViewHolder {
        ImageView iv_classify_content;
        TextView tv_classify_content;
    }
}
